package logic

import (
	"context"

	"go-zero-mall/app/admin/cmd/rpc/internal/svc"
	"go-zero-mall/app/admin/cmd/rpc/pd"

	"github.com/jinzhu/copier"
	"github.com/zeromicro/go-zero/core/logx"
)

type MenuDetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewMenuDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MenuDetailLogic {
	return &MenuDetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 菜单-详情
func (l *MenuDetailLogic) MenuDetail(in *pd.UmsMenuDetailReq) (*pd.UmsMenuDetailResp, error) {
	d, err := l.svcCtx.UmsMenuModel.FindOne(l.ctx, in.Id)
	if err != nil {
		return nil, err
	}
	var result pd.Menu
	copier.Copy(&result, d)
	return &pd.UmsMenuDetailResp{Menu: &result}, nil
}
